package com.classs05.c_other;

import com.classs05.b_object.Person;

public class Test01 {
    public static void main(String[] args) {
        Student[] students = new Student[3];
        Student student = new Student("张三", 18);
        Student student1 = new Student("李四", 30);
        Student student2 = new Student("王五", 8);
        students[0] = student;
        students[1] = student1;
        students[2] = student2;
        for (int j = 0; j < students.length - 1; j++) {
            for (int i = 0; i < students.length - 1 - j; i++) {
                //如果students[i]比students[i+1]大,就排序换位置
//                if (students[i].compareTo(students[i+1])>0){
                if (student.compare(students[i], students[i + 1]) > 0) {
                    Student temp = students[i];
                    students[i] = students[i + 1];
                    students[i + 1] = temp;
                }
            }
        }

        //遍历
        for (int i = 0; i < students.length; i++) {
            System.out.println(students[i]);
        }


//● this对象（调用compareTo方法的对象）减 指定对象（传入compareTo()的参数对象）大于0,返回正整数
//● this对象（调用compareTo方法的对象）减 指定对象（传入compareTo()的参数对象）小于0 返回负整数
//● this对象（调用compareTo方法的对象）减 指定对象（传入compareTo()的参数对象）等于0 返回零
        int i = student.compareTo(student1);
        System.out.println(i);


    }
}
